package com.jieshao.script

import com.jieshao.rule.ScriptContext
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test


class HostKtTest {

    @Test
    fun evalString_normal() {

        val scriptContext = ScriptContext()
        scriptContext.currentRevision = "c21c2173e21ad07f1f880bbc3720b72d6b2fa773"
        scriptContext.origin = "git@gitee.com:tqybt/line-share-intellij-plugin.git"
        scriptContext.lineSelection = 1 to 1
        scriptContext.projectPath = "..."
        scriptContext.filePath = "/src/main/kotlin/com/jieshao/service/LineShareRuntime.kt"

        var str = "\"\${convertGitUrl2Https(origin?:\"\")}/blob/\$currentRevision\${filePath}#L\${(\"\${lineSelection?.first}\" + if (null != lineSelection?.second && lineSelection?.first!=lineSelection?.second) \"-L\${lineSelection?.second}\" else \"\")}\""

        Assertions.assertEquals("return",evalString("\"return\"",scriptContext),)
        Assertions.assertEquals("c21c2173e21ad07f1f880bbc3720b72d6b2fa773",evalString("\"\$currentRevision\"", scriptContext))
        Assertions.assertEquals("(1, null)",evalString("lineSelection.toString()", scriptContext),)
        Assertions.assertEquals("https://gitee.com/tqybt/line-share-intellij-plugin",evalString("\"\${convertGitUrl2Https(origin)}\"", scriptContext))
        Assertions.assertEquals("https://gitee.com/tqybt/line-share-intellij-plugin",evalString("\"\${convertGitUrl2Https(origin?:\"\")}\"", scriptContext))
        Assertions.assertEquals("https://gitee.com/tqybt/line-share-intellij-plugin/blob/c21c2173e21ad07f1f880bbc3720b72d6b2fa773/src/main/kotlin/com/jieshao/service/LineShareRuntime.kt#L1",evalString(str, scriptContext),)
        scriptContext.currentRevision = "currentRevisionChange"
        Assertions.assertEquals("currentRevisionChange",evalString("\"\$currentRevision\"", scriptContext))

    }
}